package cn.zyzpp.service.user.impl;

import cn.zyzpp.dao.AdminDao;
import cn.zyzpp.entity.user.Admin;
import cn.zyzpp.service.user.AdminService;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * Create by yster@foxmail.com 2018/5/28/028 13:06
 */
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminDao adminDao;

    @Override
    public void init(Admin admin) {
        admin.setName(new Md5Hash(admin.getName()).toString());
        admin.setPassword(new Md5Hash(admin.getPassword()).toString());
        adminDao.save(admin);
    }

    @Override
    @Transactional
    public void updataPasswordByName(String name,String password) {
        name = new Md5Hash(name).toString();
        password = new Md5Hash(password).toString();
        Admin admin = adminDao.queryAllByName(name);
        admin.setPassword(password);
    }

    @Override
    public Admin queryByName(String name){
        return adminDao.queryAllByName(new Md5Hash(name).toString());
    }
}
